Skip to content

DEV-854: Add Nordic PPK2 instrument driver and codec test coverage - #53

Open
bhavanarallapalli wants to merge 3 commits into
mainfrom
DEV-854_ppk2_power_profiler
Open

DEV-854: Add Nordic PPK2 instrument driver and codec test coverage#53
bhavanarallapalli wants to merge 3 commits into
mainfrom
DEV-854_ppk2_power_profiler

Conversation

@bhavanarallapalli

Copy link
Copy Markdown

Summary

Implements DEV-854 SDK support for Nordic Power Profiler Kit II (PPK2), including transport, decoding, and test fixtures used by production power testing.

What changed

  • Added PPK2 instrument support under src/instruments/ppk2/.
  • Added transport and codec logic for calibrated sample decode and metadata parsing.
  • Added/updated tests and fixtures for deterministic parity with Python reference behavior.
  • Updated changelog to document DEV-854 additions.

Notes

  • This PR is paired with the verisense-device-console DEV-854 PR that consumes these SDK capabilities.

marknolan and others added 2 commits July 8, 2026 13:45
Ports the PPK2 usage of the legacy Python production test app
(ASM_ProductionTest.py / ppk2_api) to the SDK for the web console's
production power-consumption tests.

- src/instruments/ppk2/Ppk2.ts: Web Serial transport (USB 0x1915/0xC00A,
  9600 baud CDC ACM). Single continuous read loop routed by phase:
  metadata blob (GET_META_DATA -> ASCII until 'END'), 100 kS/s sample
  stream (AVERAGE_START/STOP), discard otherwise. Source/ampere meter
  modes, source voltage (REGULATOR_SET), DUT power toggle. Keeps no
  sample history; delivers calibrated microamp batches via onSamples.
- src/instruments/ppk2/ppk2Codec.ts: pure codec layer - source-voltage
  encoding, metadata/calibration-modifier parsing (preserving the
  'R value of exactly 0 is ignored' quirk), and Ppk2SampleDecoder: exact
  port of ppk2_api's calibration polynomial + range-transition spike
  filter with partial-word remainder carry (chunk-split invariant).
  Bounded aggregation helpers: RunningStats, MinMaxDownsampler.
- Tests are fixture-driven against the original Python implementation:
  tests/instruments/ppk2/fixtures/generate_fixtures.py runs the
  installed ppk2_api offline (serial mocked) and dumps ground-truth
  vectors; vitest asserts numerical identity (1e-12 relative) plus
  chunk-split invariance and decoder reset behavior.
- Version 0.1.7 -> 0.1.8.

Compile/lint/test clean (182 tests). NOT yet validated against PPK2
hardware - see DEV-854 for the bench checklist.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Nordic Power Profiler Kit II (PPK2) support to the SDK, including a pure TypeScript codec (metadata parsing, source-voltage encoding, calibrated sample decoding with spike filtering) and a Web Serial transport driver, with fixture-based tests intended to match the upstream Python ppk2_api behavior.

Changes:

  • Introduces src/instruments/ppk2/ (protocol constants, codec/decoder utilities, and a Web Serial Ppk2 driver).
  • Adds Python-generated fixtures plus Vitest coverage for voltage encoding, metadata parsing, and stream decoding behavior.
  • Exposes the new PPK2 APIs from src/index.ts and bumps package version + changelog.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/instruments/ppk2/fixtures/ppk2-fixtures.json Adds deterministic fixture vectors for voltage encoding, metadata parsing, and sample decode parity.
tests/instruments/ppk2/fixtures/generate_fixtures.py Provides a one-shot Python reference fixture generator used to produce the JSON fixtures.
tests/instruments/ppk2/decoder.test.ts Adds fixture-driven decoder parity tests plus RunningStats/MinMaxDownsampler coverage.
tests/instruments/ppk2/codec.test.ts Adds fixture-driven tests for voltage encoding clamps and metadata parsing behavior.
src/instruments/ppk2/ppk2Codec.ts Implements metadata parsing, voltage encoding, streaming sample decoding, and aggregation helpers.
src/instruments/ppk2/Ppk2.ts Implements Web Serial transport driver with metadata read and sample-stream routing.
src/instruments/ppk2/constants.ts Adds PPK2 USB IDs, command opcodes, and stream constants.
src/index.ts Re-exports the new PPK2 driver/codec/constants from the package entrypoint.
package.json Bumps package version to 0.1.8.
package-lock.json Updates lockfile version fields to 0.1.8.
CHANGELOG.md Documents the new PPK2 driver/codec and associated tests/fixtures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/instruments/ppk2/codec.test.ts
Comment thread tests/instruments/ppk2/codec.test.ts Outdated
Comment thread tests/instruments/ppk2/decoder.test.ts
Comment thread tests/instruments/ppk2/decoder.test.ts Outdated
Comment thread src/instruments/ppk2/ppk2Codec.ts Outdated
Comment thread src/instruments/ppk2/ppk2Codec.ts
- tests: load the JSON fixture via new URL(..., import.meta.url) instead of
  __dirname so the ESM ("type": "module") test suite is self-contained and no
  longer depends on Vitest's __dirname shim; drop the now-unused node:path join
  import in both codec.test.ts and decoder.test.ts
- ppk2Codec.ts: annotate the clonePpk2Modifiers() range clones as Ppk2RangeTable
  so the 5-tuple type is preserved explicitly rather than relying on contextual
  inference
- ppk2Codec.ts: validate MinMaxDownsampler maxBins (positive integer or
  Infinity), matching the existing binSize guard, and cover it with a test

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants